#delimit;
pause on;
clear all;
set mem 50m;
pause;
set more off;
pause;
cd "C:\data\Veto points\JOP_December08\Replication";
pause;
use "veto0208_replication_v2.dta", clear;
save "veto0208_replication_v3.dta", replace;
log using panel.smcl, replace;


/*CREATION OF VARIABLES AND LAG STRUCTURES*/

/*Reforms in Positive Direction*/
generate change_mag_positive=d.EBRD;
replace change_mag_positive=0 if d.EBRD<=0 & d.EBRD !=.;
lab var change_mag_positive "Size of Positive Shift in EBRD Scores (if positive score)";

/*Generate Cumulative Positive Movements*/
generate ebrd_mag_pos = change_mag_positive+l.EBRD;

/*Generate Interaction with Lagged Reform*/
generate inter_checks_lagEBRD=checks_new*lag_EBRD;

/*Generate Interaction with 2 Lags of  Reform*/
gen inter_checks_L2EBRD = checks_new*L2.EBRD;

/*Generate Interaction with No Lag of Reform*/
gen inter_checks_EBRD = checks_new*EBRD;


/*Generate Interaction Lag of Reform and Political Competition*/
generate inter_parcomp_lagEBRD=p_parcomp*lag_EBRD;

pause;


/***********************************************************************************************************************************************/

/*Table 1: Panel (OLS and Arellano Bond Analysis)*/

/*Model 1: OLS with Year Fixed Effects*/
xi3: xtreg ebrd_mag_pos checks_new l.EBRD inter_checks_lagEBRD   i.year if country_<26, robust;
outreg2 using Table1, e(all) bdec(3) tdec(3) replace;

/*Model 2: OLS, Year FE, Control Variables*/
xi3: xtreg ebrd_mag_pos checks_new postcoms l.EBRD inter_checks_lagEBRD  wart ln_gdpcap i.year if country_<26,  robust;
outreg2 using Table1, e(all) bdec(3) tdec(3);

/*Model 3: OLS with Two-Way Fixed Effects*/
xi3: xtreg ebrd_mag_pos checks_new l.EBRD inter_checks_lagEBRD   i.year if country_<26, fe robust;
outreg2 using Table1, e(all) bdec(3) tdec(3);

/*Model 4: OLS with Two-Way Fixed Effects, Control Variables*/
xi3: xtreg ebrd_mag_pos checks_new postcoms l.EBRD inter_checks_lagEBRD  wart ln_gdpcap i.year if country_<26, fe robust;
outreg2 using Table1, e(all) bdec(3) tdec(3);

/*Model 5: Arellano Bond, No Controls*/
xi: xtabond2 ebrd_mag_pos L.EBRD checks_new inter_checks_lagEBRD  i.year if country_<26, gmm(L.EBRD inter_checks_lagEBRD, 
laglim(1 1) ) iv(checks_new i.year) noleveleq nomata robust;
outreg2 using Table1, e(all) bdec(3) tdec(3);

/*Model 6: Arellano Bond, Controls*/
xi: xtabond2 ebrd_mag_pos L.EBRD checks_new postcoms inter_checks_lagEBRD  wart ln_gdpcap  i.year if country_<26, 
gmm(L.EBRD inter_checks_lagEBRD L.ln_gdpcap, 
laglim(1 1)) iv(checks_new postcoms i.year wart) noleveleq nomata robust;
outreg2 using Table1, e(all) bdec(3) tdec(3);

/*Model 7: Arellano Bond, Checks Endogenized, No Controls*/
xi: xtabond2 ebrd_mag_pos L.EBRD checks_new  inter_checks_lagEBRD i.year if country_<26, 
gmm(L.EBRD L.checks_new  L.inter_checks_lagEBRD, laglim(1 1) ) iv(i.year ) noleveleq nomata robust;
outreg2 using Table1, e(all) bdec(3) tdec(3);

/*Model 8: Arellano Bond, Checks Endogenized, Controls*/
xi: xtabond2 ebrd_mag_pos L.EBRD checks_new postcoms inter_checks_lagEBRD  wart ln_gdpcap  i.year if country_<26, 
gmm(L.EBRD L.checks_new L.postcoms L.inter_checks_lagEBRD L.ln_gdpcap , laglim(1 1)) iv(i.year wart) noleveleq nomata robust;
outreg2 using Table1, e(all) bdec(3) tdec(3);

/*Model 9: Arellano Bond, Checks Endogenized, No Controls, Dealing with Political Competition*/
xi: xtabond2 ebrd_mag_pos L.EBRD checks_new  p_parcomp inter_checks_lagEBRD inter_parcomp_lagEBRD i.year if country_<26, 
gmm(L.EBRD L.checks_new l.p_parcomp l.inter_checks_lagEBRD l.inter_parcomp_lagEBRD , laglim(1 1)) iv(i.year) noleveleq nomata robust;
outreg2 using Table1, e(all) bdec(3) tdec(3);

/*Model 10: Arellano Bond, Checks Endogenized, Controls, Dealing with Political Competition*/
xi: xtabond2 ebrd_mag_pos L.EBRD checks_new postcoms  wart ln_gdpcap p_parcomp inter_checks_lagEBRD inter_parcomp_lagEBRD i.year if country_<26, 
gmm(L.EBRD L.checks_new L.postcoms l.p_parcomp l.inter_checks_lagEBRD l.inter_parcomp_lagEBRD L.ln_gdpcap, 
laglim(1 1)) iv(i.year wart) noleveleq nomata robust;
outreg2 using Table1, e(all) bdec(3) tdec(3) excel;
pause;



/********************************************SUMMARY STATISTICS AND CORRRELATIONS**********************************************/

/*Table A2 Summary Statistics - Panel Variables*/
xi3: xtreg ebrd_mag_pos checks_new postcoms l.EBRD inter_checks_lagEBRD  wart ln_gdpcap i.year if country_<26,  robust;
estat sum;


xi: xtabond2 ebrd_mag_pos L.EBRD checks_new postcoms  wart ln_gdpcap p_parcomp inter_checks_lagEBRD inter_parcomp_lagEBRD i.year if country_<26, 
gmm(L.EBRD L.checks_new L.postcoms l.p_parcomp l.inter_checks_lagEBRD l.inter_parcomp_lagEBRD L.ln_gdpcap, laglim(1 1)) iv(i.year wart) noleveleq nomata robust;
estat sum p_parcomp  inter_parcomp_lagEBRD;
pause;


/*Table A3 Bivariate Correlations - Panel Variables*/
pwcorr ebrd_mag_pos checks_new postcoms L.EBRD inter_checks_lagEBRD  wart ln_gdpcap p_parcomp inter_parcomp_lagEBRD if country_<26, star(5);
pause;


save "veto0208_replication_v3.dta", replace;
/**********************************************************************************************************************************************/

/*FIGURE 2*/
/*GENERATION OF RESULTS FOR FIGURE 2*/
#delimit;
xi: xtabond2 ebrd_mag_pos L.EBRD checks_new postcoms inter_checks_lagEBRD  wart ln_gdpcap  i.year if country_<26, 
gmm(L.EBRD L.checks_new L.postcoms L.inter_checks_lagEBRD L.ln_gdpcap , laglim(1 1)) iv(i.year wart) noleveleq nomata robust;

foreach num of numlist 0(1)100 {;
lincom 1.667724*checks_new+1.667724*`num'*inter_checks_lagEBRD, level(95);
};


/*RESULTS WERE PASTED INTO A FILE CALLED LINCOM.DTA*/

/*CREATING FIGURE 2 USING ABOVE ANALYSIS*/

use lincom.dta, clear;
drop if ebrd > 87;

twoway  (scatter  lincom_coef ebrd, msymbol(diamond) msize(small) mcolor(bluishgray)) (rspike  high low ebrd, lcolor (gs7) lwidth(medthin)), 
xtitle(Economic Reform at Time t-1) ytitle("Estimated Effect of Veto Players on" "Reform Magnitude at Time t") xlabel(0(5)85, labsize(small))  
yline(0, lwidth(med) lpattern(dash) lcolor(gs2)) xline(46.1, lwidth(med) lpattern(dot) lcolor(gs2)) legend(off);

graph save lincom_bw.gph, replace;
graph export lincom_bw.eps, as(eps) preview(off) replace;
pause;


log close;
